This is a simple example of Locally Linear Embedding (LLE) using Python and the scikit-learn library.
Locally Linear Embedding (LLE) is a technique for nonlinear dimensionality reduction. It aims to preserve the local relationships between data points in high-dimensional space while mapping them to a lower-dimensional space. LLE achieves this by modeling each data point as a linear combination of its nearest neighbors and finding a low-dimensional representation that preserves these local linear relationships.
Key concepts of LLE:
LLE is particularly useful for capturing the underlying structure of data when it lies on a low-dimensional manifold within the high-dimensional space.
Python Source Code:
# Import necessary libraries
import numpy as np
import matplotlib.pyplot as plt
from sklearn.datasets import make_swiss_roll
from sklearn.manifold import LocallyLinearEmbedding
# Generate synthetic data in the shape of a swiss roll
X, color = make_swiss_roll(n_samples=1000, random_state=42)
# Apply Locally Linear Embedding (LLE) for dimensionality reduction
lle = LocallyLinearEmbedding(n_neighbors=12, n_components=2, random_state=42)
X_lle = lle.fit_transform(X)
# Plot the original and embedded data
plt.figure(figsize=(12, 6))
# Plot the original swiss roll
plt.subplot(1, 2, 1)
plt.scatter(X[:, 0], X[:, 2], c=color, cmap='viridis', marker='o', edgecolors='k')
plt.title('Original Swiss Roll')
plt.xlabel('Feature 1')
plt.ylabel('Feature 2')
# Plot the embedded swiss roll using LLE
plt.subplot(1, 2, 2)
plt.scatter(X_lle[:, 0], X_lle[:, 1], c=color, cmap='viridis', marker='o', edgecolors='k')
plt.title('Locally Linear Embedding (LLE)')
plt.xlabel('Embedding Dimension 1')
plt.ylabel('Embedding Dimension 2')
plt.tight_layout()
plt.show()
Explanation: